﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Design;
using System.ComponentModel;
using Silver.UI;
using System.Windows.Forms;
using SharedClasses;
using UIDesigner.DesignContainers;
using DesignerHost;

namespace UIDesigner.Designers
{
    public class ObjectUIActionList : DesignerActionList
    {
        public ObjectUIActionList(IComponent component) : base(component)
        {
            this.AutoShow = true;
        }

        public void EditSurfaceProperties()
        {
            ObjectControlContainer ctrlContainer = (ObjectControlContainer)this.Component;
            PropertyGrid ctrlPropertyGrid = (PropertyGrid) this.ServiceProvider.GetService(typeof(PropertyGrid));
            PropertyGridPanel ctrlPropertyGridPanel = (PropertyGridPanel) ctrlPropertyGrid.Parent;
            IDesignerActionUIService objSvc = (IDesignerActionUIService)this.ServiceProvider.GetService(typeof(IDesignerActionUIService));
            objSvc.HideUI((IComponent)this.Component);

            ctrlPropertyGridPanel.SelectSurfaceProperties(ctrlContainer);
        }

        public void RemoveSurfaceControls()
        {
            ObjectControlContainer ctrlContainer = (ObjectControlContainer)this.Component;

            ctrlContainer.RemoveSurfaceControls(); 
        }

        private IServiceProvider ServiceProvider
        {
            get
            {
                AFDesignerHost objHost = (AFDesignerHost)this.Component.Site.Container;

                return (IServiceProvider)objHost;
            }
        }

        public override DesignerActionItemCollection GetSortedActionItems()
        {
            DesignerActionItemCollection rgActionItems = new DesignerActionItemCollection();
            ObjectControlContainer ctrlContainer = (ObjectControlContainer)this.Component;

            rgActionItems.Add(new DesignerActionMethodItem(this, "EditSurfaceProperties", "Edit Surface Properties"));
            rgActionItems.Add(new DesignerActionPropertyItem("LayoutMode", "Layout Mode", "Appearance", "Selects the layout of the controls."));

            if (ctrlContainer.HasSurfaceControls)
            {
                rgActionItems.Add(new DesignerActionMethodItem(this, "RemoveSurfaceControls", "Remove Surface Controls"));
            }

            foreach (DesignerActionItem objItem in rgActionItems)
            {
                DesignerActionPropertyItem objPropertyItem = objItem as DesignerActionPropertyItem;

                if (objPropertyItem != null)
                {
                    objPropertyItem.RelatedComponent = this.Component;
                }
            }

            return rgActionItems;
        }
    }
}
